package com.yc.controller;


import com.github.pagehelper.PageHelper;
import com.yc.common.utils.UploadFileUtil;
import com.yc.service.impl.AttendanceSheetServiceImpl;
import com.yc.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mqm
 * @since 2023-07-27
 */
//@RestController
public class AttendanceSheetController {

    @Resource
    private AttendanceSheetServiceImpl attendanceSheetService;

    @ApiOperation("学生的考勤状态的信息")
    @PostMapping("wx/queryStuAttendanceInfo")
    public Result queryStuAttendanceInfo(@RequestParam("stuid") String stuid, @RequestParam("page") int page){
        PageHelper.startPage(page,8);
        List<Map<String, Object>> list = attendanceSheetService.queryStuAttendanceInfo(stuid);
        return Result.success(list);
    }
//    @ApiOperation("考勤申诉图片位置")
//    @PostMapping("wx/uploadAttendance")
//    public Result demo(List<MultipartFile> file, HttpServletRequest request){
//        String picRootName = "uploadAttendance"; // 上传到本地的文件夹名（自己定义
//        // 调用工具类将文件保存到本地 并获取返回值（Map类型 数据是文件信息
//        Map<String, UploadFileUtil.UploadFile> stringUploadFileMap
//                = UploadFileUtil.uploadFiles(request, file, picRootName);
//        String originalFilename = file.get(0).getOriginalFilename(); // 获取文件名（用于查找map集合中的新地址
//        String newFilePath = stringUploadFileMap.get(originalFilename).getNewFileUrl(); // 获取map中的新地址
//        return Result.success("上传成功",newFilePath);
//    }

    @ApiOperation("添加申诉数据")
    @PostMapping("wx/insertStuAttendanceInfo")
    public Result insertStuAttendanceInfo(@RequestParam("stuid") String stuid, @RequestParam("description") String description,
                                         @RequestParam("coursename") String coursename,@RequestParam("time") String time,
                                          @RequestParam("Attid") int Attid , @RequestParam("imagePath") String imagePath,
                                          @RequestParam("changeStatus") int changeStatus){
        attendanceSheetService.insertStuAttendanceInfo(stuid, description, coursename, time, Attid, imagePath,changeStatus);
        return Result.success("上传成功!");
    }

    @ApiOperation("教师查看自己班级的申诉信息")
    @PostMapping("wx/queryStuAttendanceInfoByTea")
    public Result queryStuAttendanceInfoByTea( @RequestParam("page") int page, @RequestParam("username") String username){
        PageHelper.startPage(page, 8);
        List<Map<String, Object>> maps = attendanceSheetService.queryStuAttendanceInfoByTea(username);
        return Result.success(maps);
    }

    @ApiOperation("查询内容，图片地址")
    @PostMapping("wx/queryImagePath")
    public Result queryImagePath( @RequestParam("id") int id){

        Map<String, Object> map = attendanceSheetService.queryimagePath(id);
        return Result.success(map);
    }

    @ApiOperation("修改状态")
    @PostMapping("wx/updateStatus")
    public Result updateStatus(@RequestParam("stuid") String stuid , @RequestParam("Attid") int Attid, @RequestParam("status") int status){
        attendanceSheetService.updateAttidStatus(stuid,Attid);
        attendanceSheetService.updateStatus(stuid,Attid,status);
        return Result.success("处理成功");
    }
    @ApiOperation("老师不同意并且回复内容")
    @PostMapping("wx/updateSta")
    public Result updateStatus2(String stuid,int Attid , @RequestParam("teacherReply") String teacherReply ){
        attendanceSheetService.updateAttidStatus2(stuid,Attid,teacherReply);
        return Result.success("处理成功!");
    }

    @ApiOperation("学生查询自己申诉的内容")
    @PostMapping("wx/queryAttendenceImagePath")
    public Result queryAttendenceImagePath( @RequestParam("id") int id){
        Map<String, Object> map = attendanceSheetService.queryAttendenceImagePath(id);
        return Result.success(map);
    }

}

